﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using XLib.Node;

namespace NodeLib.Sample
{
    public class Func_CustomFunc : NodeBase
    {
        public override void Init()
        {
            SetViewProperty(NodeColorSet.Data, "Variate", "自定义函数");

            PinGroupList.Add(new ExecutePinGroup(this, "触发"));
            PinGroupList.Add(new FuncDataPinGroup(this, "自定义函数")
            {
                Readable = true,
                Writeable = false
            });

            InitPinGroup();
        }

        public override string GetTypeString() => nameof(Func_CustomFunc);

        public override Dictionary<string, object> GetParaDict()
        {
            Dictionary<string, object> result = new Dictionary<string, object>
            {
                { "Data", GetData(1) },
            };
            return result;
        }

        public override void LoadParaDict(string version, Dictionary<string, object> paraDict)
        {
            SetData(1, paraDict["Data"]);
        }

        protected override NodeBase CloneNode() => new Func_CustomFunc();

        protected override void ExecuteNode()
        {
            FuncDataPinGroup funcDataPinGroup = (FuncDataPinGroup)PinGroupList[1];
            funcDataPinGroup.RunFunc(funcDataPinGroup.SelectedFuncName);
        }
    }
}
